
<?php
ini_set('date.timezone','Asia/Shanghai');
error_reporting(E_ERROR);
require_once "../lib/WxPay.Api.php";
require_once 'log.php';

//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);

$out_trade_no   = $_GET['no'];//商户订单编号
$refund         = $_GET['refund'];//退款金额
$refund_fee     = sprintf("%.2f", ($refund-($refund*0.006)))*100;
$total_fee      = $_GET['total']*100;//订单总金额  ;

//商户订单号退款
if(isset($out_trade_no) && $out_trade_no != ""){
	$out_trade_no = $out_trade_no;
	$total_fee    = $total_fee;
	$refund_fee   = $refund_fee;
	$input        = new WxPayRefund();
	$input->SetOut_trade_no($out_trade_no);
	$input->SetTotal_fee($total_fee);
	$input->SetRefund_fee($refund_fee);
    //商户退款单号
    $refund_no = WxPayConfig::MCHID.date("YmdHis");
    $input->SetOut_refund_no($refund_no);

    $input->SetOp_user_id(WxPayConfig::MCHID);
    $result = WxPayApi::refund($input);
    //$result = json_decode($result);
    echo json_encode(array("result"=>$result,"no"=>$refund_no));
	//printf_info(WxPayApi::refund($input));
	//exit();
}
//微信订单号退款
/*if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
    $transaction_id = $_REQUEST["transaction_id"];
    $total_fee = $_REQUEST["total_fee"];
    $refund_fee = $_REQUEST["refund_fee"];
    $input = new WxPayRefund();
    $input->SetTransaction_id($transaction_id);
    $input->SetTotal_fee($total_fee);
    $input->SetRefund_fee($refund_fee);
    $input->SetOut_refund_no(WxPayConfig::MCHID.date("YmdHis"));
    $input->SetOp_user_id(WxPayConfig::MCHID);
    printf_info(WxPayApi::refund($input));
    exit();
}*/
?>
